package com.singlemountain.gcommerce.dao;

import com.googlecode.genericdao.dao.jpa.GenericDAOImpl;
import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.jpa.JPASearchProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: sleepingsun
 * Date: 12-2-17
 * Time: 下午5:38
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class BaseDao<T, ID extends Serializable> extends GenericDAOImpl<T, ID> {
    @Override
    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) {
        super.setEntityManager(entityManager);
    }

    @Override
    @Autowired
    public void setSearchProcessor(JPASearchProcessor searchProcessor) {
        super.setSearchProcessor(searchProcessor);
    }

    public EntityManager getEntityManager() {
        return em();
    }

    public Search searchEqual(String property, String value){
        Search search=new Search();
        search.addFilterEqual(property,value);
        return  search;
    }
}
